package com.app.newiptv.bean;

import android.os.Parcel;
import java.util.ArrayList;
import java.util.Comparator;


public class Channel extends Content  implements Comparator<Channel>  {
    /**
     * 频道逻辑号
     */
    public String channelNumber;
    /**
     * 节目单
     */
    public ArrayList<Program> programs;

    public Channel() {
        super();
        channelNumber = "000";
        programs = new ArrayList<>();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(parentID);
        dest.writeString(contentID);
        dest.writeString(channelNumber);
        dest.writeString(name);
        dest.writeParcelable(imgSource, flags);
        dest.writeTypedList(programs);
        dest.writeInt(isHistory);
    }

    public static final Creator<Channel> CREATOR = new Creator<Channel>() {
        @Override
        public Channel createFromParcel(Parcel source) {
            ArrayList<Program> programs = new ArrayList<>();
            String parentID = source.readString();
            String contentId = source.readString();
            String channelNumber = source.readString();
            String channelName = source.readString();
            ImageSource imgSource = source.readParcelable(ImageSource.class.getClassLoader());
            source.readTypedList(programs, Program.CREATOR);
            int isHistory = source.readInt();

            Channel channel = new Channel();
            channel.parentID = parentID;
            channel.contentID = contentId;
            channel.channelNumber = channelNumber;
            channel.name = channelName;
            channel.programs = programs;
            channel.imgSource = imgSource;
            channel.isHistory = isHistory;
            return channel;
        }

        @Override
        public Channel[] newArray(int size) {
            return new Channel[size];
        }
    };

    @Override
    public String toString() {
        return "Channel{" +
                "parentID=" + parentID +
                ", contentID=" + contentID +
                ", name=" + name +
                ", channelNumber='" + channelNumber + '\'' +
                ", programs=" + programs +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || !(o instanceof Channel)) {
            return false;
        } else {
            try {
                return ((Channel) o).contentID.equals(contentID);
            } catch (Exception e) {
                return false;
            }
        }
    }

	@Override
	public int compare(Channel lhs, Channel rhs) {
		// TODO Auto-generated method stub
		return Integer.parseInt(lhs.channelNumber) - Integer.parseInt(rhs.channelNumber);
	}
}




